package com.pureut.system.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.system.domain.dto.DrviceRecordDto;
import com.pureut.system.domain.vo.DrviceRecordVo;
import com.pureut.system.service.DrviceRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: CM
 * @date: 2023/2/13  11:23
 */
@RestController
@RequestMapping("/drvice")
public class DrviceRecordController extends BaseController {

    @Resource
    private DrviceRecordService drviceRecordService;

    /**
     * 设备台账查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DrviceRecordVo drviceRecordVo)
    {
        startPage();
        List<DrviceRecordDto> list = drviceRecordService.getList(drviceRecordVo);
        return getDataTable(list);
    }

    /**
     * 新增设备台账
     */
    @Log(title = "新增设备台账  ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody DrviceRecordVo drviceRecordVo) throws Exception {
        return toAjax(drviceRecordService.drviceAdd(drviceRecordVo));
    }

    /**
     * 修改设备台账
     */
    @Log(title = "修改设备台账", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated DrviceRecordVo drviceRecordVo){
        return toAjax(drviceRecordService.drviceEdit(drviceRecordVo));
    }

    /**
     * 查看设备台账明细
     */
    @GetMapping("/view")
    public AjaxResult view(long id)
    {
        return AjaxResult.success(drviceRecordService.view(id));
    }

    /**
     * 删除设备台账信息
     */
    @Log(title = "删除配置变量", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public AjaxResult remove(String ids){
        return toAjax(drviceRecordService.remove(ids));
    }

    /**
     * 通过线别编码查看列表信息
     */
    @GetMapping("/getLine")
    public AjaxResult getLine(String lineCode)
    {
        return AjaxResult.success(drviceRecordService.getLine(lineCode));
    }

    /**
     * 通过设备编码查出设备名称,设备类型,设备属性
     */
    @GetMapping("/getDrviceInfo")
    public AjaxResult getDrviceInfo(String drviceCode)
    {
        return AjaxResult.success(drviceRecordService.getDrviceInfo(drviceCode));
    }

}
